package day3;

import day1.Student;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * ClassName：TestTreeSet2
 *
 * @Author：小鱼
 * @Create：2025-08-13 10:19
 */
public class TestTreeSet2 {
    public static void main(String[] args) {
        //第一步：创建实现类
        Comparator<Student> comparator = new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //age升序
                int num = o1.getAge()-o2.getAge();

                if(num==0){
                    //name降序
                    num = -(o1.getName().compareTo(o2.getName()));
                }

                return num;
            }
        };
        //按comparator这个规则来比
        Set<Student> set = new TreeSet<>(comparator);
        Student s1 = new Student("zs",18);
        Student s4 = new Student("zs",22);
        Student s2 = new Student("ls",18);
        Student s3 = new Student("ww",19);
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        System.out.println("set: "+set);

    }
}
